package com.ssy.system.controller;

import com.ssy.common.utils.PageResult;
import com.ssy.common.utils.Result;
import com.ssy.system.pojo.Dictionaries;
import com.ssy.system.service.IDictionariesService;
import com.ssy.system.vo.DictionariesVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * @author ssy
 */
@RestController
@RequestMapping("/dic")
public class DictionariesController {

    @Autowired
    private IDictionariesService dictionariesService;

    /**
     * 字典的分页查询
     *
     * @param dic
     * @return
     */
    @GetMapping("/loadAllDictionaries")
    public PageResult loadAllDictionaries(DictionariesVo dic) {
        return this.dictionariesService.loadAllDictionaries(dic);
    }

    /**
     * 添加字典
     *
     * @param dic
     * @return
     */
    @PostMapping("/addDictionaries")
    public Result addDictionaries(@RequestBody Dictionaries dic) {
        dic.setCreateTime(new Date());
        return this.dictionariesService.saveDictionaries(dic);
    }

    /**
     * 删除字典
     *
     * @param id
     * @return
     */
    @DeleteMapping("/deleteDepartment/{id}")
    public Result deleteDepartment(@PathVariable Integer id) {
        return this.dictionariesService.deleteDictionaries(id);
    }

    /**
     * 批量删除字典
     *
     * @param ids
     * @return
     */
    @DeleteMapping("/bathDepartment/{ids}")
    public Result bathDepartment(@PathVariable Integer[] ids) {
        return this.dictionariesService.bathDictionaries(ids);
    }

    /**
     * 修改字典
     *
     * @param dic
     * @return
     */
    @PostMapping("/updateDepartment")
    public Result updateDepartment(@RequestBody Dictionaries dic) {
        return this.dictionariesService.updateDictionaries(dic);
    }

    /**
     * 修改字典状态
     *
     * @param id
     * @param state
     * @return
     */
    @PostMapping("/updateDepartmentState/{id}/{state}")
    public Result updateDepartmentState(@PathVariable Integer id, @PathVariable Integer state) {
        Dictionaries dictionaries = new Dictionaries();
        dictionaries.setId(id);
        dictionaries.setState(state);
        return this.dictionariesService.updateDictionaries(dictionaries);
    }

}
